#pragma once
#include <ctemplate/template.h>

#include "../comm/comm.hpp"
#include "model.hpp"

const std::string all_html_path = "./html_ctemplate/all_questions.html";
const std::string one_html_path = "./html_ctemplate/one_question.html";

class View
{
public:
    void AllQuestionsHtml(const std::vector<Question> &questions, std::string *html)
    {

        // 形成数字典
        ctemplate::TemplateDictionary root("all");
        // root.SetFilename()
        for (auto &e : questions)
        {
            ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
            sub->SetValue("number", e._number);
            sub->SetValue("title", e._title);
            sub->SetValue("star", e._star);
        }

        // 获取被渲染的html
        ctemplate::Template *tpl = ctemplate::Template::GetTemplate(all_html_path, ctemplate::DO_NOT_STRIP);
        // 开始渲染，返回新的结果到html
        tpl->Expand(html, &root);
    }

    void OneQuestionHtml(const Question &question, std::string *html)
    {
        ctemplate::TemplateDictionary root("one_question");
        root.SetValue("number", question._number);
        root.SetValue("title", question._title);
        root.SetValue("star", question._star);
        root.SetValue("desc", question._desc);
        root.SetValue("header", question._header);

        ctemplate::Template * tpl = ctemplate::Template::GetTemplate(one_html_path, ctemplate::DO_NOT_STRIP);
        tpl->Expand(html, &root);
    }

private:
};